package cc.rengu.igas.route.common.dao.impl;

import cc.rengu.igas.route.common.dao.OpmsBankSupportCfgMapper;
import cc.rengu.igas.route.common.entity.OpmsBankSupportCfgInfo;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 支持银行列表配置表(T_P_BANK_SUPPORT_CFG) 操作实现
 * Copyed by xlz on 2020/3/27 from opms module.
 *
 * @author xlz
 * @version 1.0
 * @date 2020-04-27
 */
public class OpmsBankSupportCfgMapperImpl implements OpmsBankSupportCfgMapper {

    @Override
    public List<OpmsBankSupportCfgInfo> selectChannelSupport(String instId, String dstChannelId, String supportBizType) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.OPMS_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.OPMS_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "RouteChannelSupportList");

        OpmsBankSupportCfgInfo info = new OpmsBankSupportCfgInfo();
        info.setInstId(instId);
        info.setDstChannelId(dstChannelId);
        info.setSupportBizType(supportBizType);

        List<Object> objects = dbsUtil.dbsFetchLimitListData(sqlStr, info, OpmsBankSupportCfgInfo.class);
        return objects.stream().map(item -> (OpmsBankSupportCfgInfo) item).collect(Collectors.toList());
    }
}
